<h2>Why is this an issue?</h2>
<p>Most checks against an <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof">IndexOf</a> value compare it with -1 because
<strong>0 is a valid index</strong>.</p>
<pre>
strings.IndexOf(someString) = -1  ' Test for "index not found"
strings.IndexOf(someString) &lt; 0   ' Test for "index not found"
strings.IndexOf(someString) &gt;= 0  ' Test for "index found"
</pre>
<p>Any checks which look for values <code>&gt; 0</code> ignore the first element, which is likely a bug. If the intent is merely to check the
inclusion of a value in a <code>String</code>, <code>List</code>, or array, consider using the <a
href="https://learn.microsoft.com/en-us/dotnet/api/system.string.contains">Contains</a> method instead.</p>
<pre>
strings.Contains(someString) ' Boolean result
</pre>
<p>This rule raises an issue when the output value of any of the following methods is tested against <code>&gt; 0</code>:</p>
<ul>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.ilist.indexof">IndexOf</a>, applied to <code>String</code>, list or
  array </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.indexofany">IndexOfAny</a>, applied to a <code>String</code> </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof">LastIndexOf</a>, applied to a <code>String</code>, list or
  array </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexofany">LastIndexOfAny</a>, applied to a <code>String</code> </li>
</ul>
<pre>
someArray.IndexOf(someItem) &gt; 0        ' Noncompliant: index 0 missing
someString.IndexOfAny(charsArray) &gt; 0  ' Noncompliant: index 0 missing
someList.LastIndexOf(someItem) &gt; 0     ' Noncompliant: index 0 missing
someString.LastIndexOf(charsArray) &gt; 0 ' Noncompliant: index 0 missing
</pre>
<h2>How to fix it</h2>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
Dim Color As String = "blue"
Dim Name As String = "ishmael"

Dim Strings As New List(Of String)
Strings.Add(Color)
Strings.Add(Name)
Dim StringArray As String() = Strings.ToArray()

If Strings.IndexOf(Color) &gt; 0 Then ' Noncompliant
  ' ...
End If

If Name.IndexOf("ish") &gt; 0 Then ' Noncompliant
  ' ...
End If

If Name.IndexOf("ae") &gt; 0 Then ' Noncompliant
  ' ...
End If

If Array.IndexOf(StringArray, Color) &gt; 0 Then ' Noncompliant
  ' ...
End If
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
Dim Color As String = "blue"
Dim Name As String = "ishmael"

Dim Strings As New List(Of String)
Strings.Add(Color)
Strings.Add(Name)
Dim StringArray As String() = Strings.ToArray()

If Strings.IndexOf(Color) &gt; -1 Then
  ' ...
End If

If Name.IndexOf("ish") &gt;= 0 Then
  ' ...
End If

If Name.Contains("ae") Then
  ' ...
End If

If Array.IndexOf(StringArray, Color) &gt;= 0 Then
  ' ...
End If
</pre>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.contains">String.Contains Method</a> </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.indexofany">String.IndexOfAny Method</a> </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof">String.LastIndexOf Method</a> </li>
  <li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexofany">String.LastIndexOfAny Method</a> </li>
</ul>

